﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NPCCollider : MonoBehaviour 
{
	private TeamAble teamAble;
	private MotionController controller;
	private LifeController lifeController;
	private PhotonView photView;
	void Awake()
	{
		controller = transform.root.GetComponent<MotionController>();
		lifeController = transform.root.GetComponent<LifeController>();
		teamAble = transform.root.GetComponent<TeamAble>();
		photView = transform.root.GetComponent<PhotonView>();
	}


	void OnTriggerEnter(Collider collider)
	{	if (photView.isMine || (photView.isSceneView && PhotonNetwork.isMasterClient))
	{
		LifeController lc = collider.transform.root.GetComponent<LifeController>();
		if (lc != null && !lc.isDead && !lifeController.isDead)
		{	
			TeamAble ta = collider.transform.root.GetComponent<TeamAble>();
			if (ta != null && ta.team != teamAble.team && ta.team != 3 && ta.isPlayer && !controller.attacker.attacking)
			{	
			controller.Attack(lc);
			}
		}

	}
		
	}
}
